<template>
	<keep-alive>
		<view class="centers">
			<view class="wai" @touchend='end'>
				<view class="indexClass" ref="indexClass"></view>
				<view class="buy" ref='timeline' v-for="(item,index) in buys" :key='item.id'>
					<image :src="item.icon" mode="widthFix" class="masonry"></image>
					<view class="title">
						<text class="title_t">{{item.type_name}}</text><text class="title_t">{{item.price}} SMK</text>
						<view class="title_f">
							<text>总储量:{{item.reserve}} </text>
						</view>
					</view>
					<!-- 激活 -->
					<view v-if="item.status == 4" class="yuan" @tap="activate(item.id,item.activate)"></view>
					<!-- 启动 -->
					<view v-if="item.status == 0" class="yuans" @tap="launch(item.id)"> </view>
					<!-- 已启动5 -->
					<view v-if="item.status == 1" class="yuanss"></view>
				</view>
			</view>
		</view>

	</keep-alive>
</template>

<script>
	export default {
		data() {
			return {
				buys: [],
				selecter: '',
				cunt: 0,
				top: ''
			}
		},
		onNavigationBarButtonTap(){
				window.location.reload()
			},
		onShow() {
			//矿机列表
			this.buy()

		},

	
		methods: {
			end(e) {
				this.top = this.$refs.indexClass.$el.getBoundingClientRect().top
				if (this.top > 0) {
					uni.startPullDownRefresh({
						success: () => {
							window.location.reload()
						}
					});
				}
			},
			buy() {
				this.$ajax(
					this.apiList.MineMachineryByUserId, {
						userId: uni.getStorageSync('userinfo').userId
					},
					'POST'
				).then(res => {
					this.buys = res.data

				})
			},
			//激活
			activate(id, activate) {
				uni.showModal({
					title: '激活矿机费用为',
					content: `${activate} SMK`,
					success: (res) => {
						if (res.confirm) {
							this.$ajax(
								'/bi/activateMineMachinery', {
									id: id
								},
								'POST'
							).then(res => {
								if (res.resultCode == 1) {
									this.buy()

								}
							})
						}
					}
				})
			},
			//启动
			launch(id) {

				this.$ajax(
					'/bi/startupMineMachinery', {
						id: id
					},
					'POST'
				).then(res => {
					if (res.resultCode == 1) {
						this.buy()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.centers {
		box-sizing: border-box;
		background-color: #0E1B45;
		padding: 30upx;
		height: 100%;
		width: 100%;
		overflow: hidden;
		overflow-y: scroll;

		.wai {

			.buy {
				width: 100%;
				height: 180upx;
				border-radius: 10upx;
				background-color: rgba(13, 29, 76, 1);
				border: 1upx solid #20D6D9;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20upx;
				padding: 40upx;

				.masonry {
					width: 100upx;
				}

				.title {
					.title_t {
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						margin-right: 50upx;
						color: #fff;
					}

					.title_f {
						margin-top: 20upx;

						text {
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #fff;
						}
					}
				}

				.selecter {
					width: 46upx;
				}

				.yuan {
					margin-left: 50upx;
					width: 65px;
					height: 30px;
					border-radius: 10upx;
					background: url(../../static/bizhan/s14.png) no-repeat;
					background-size: 100% 100%;
				}

				.yuans {
					width: 65px;
					height: 30px;
					border-radius: 10upx;
					background: url(../../static/bizhan/s15.png) no-repeat;
					background-size: 100% 100%;
				}

				.yuanss {
					width: 65px;
					height: 30px;
					border-radius: 10upx;
					background: url(../../static/bizhan/s16.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}


		.btn {
			width: 100%;
			height: 90upx;
			background-color: #0297FE;
			color: #fff;
			text-align: center;
			line-height: 90upx;
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: 500;
			border-radius: 10upx;
			margin-top: 30upx;
		}
	}
</style>
